namespace PMS.BLL
{
    using PMS.DBUtility;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Text;

    public class AuthorityOrganBLL
    {
        public List<AuthorityOrgan> GetList(int adminID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * ");
            builder.Append(" FROM view_AuthorityOrgan WHERE adminID=").Append(adminID);
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            AuthorityOrgan item = null;
            List<AuthorityOrgan> list = null;
            if (table.Rows.Count > 0)
            {
                list = new List<AuthorityOrgan>();
                foreach (DataRow row in table.Rows)
                {
                    item = new AuthorityOrgan();
                    if (row["AdminID"].ToString() != "")
                    {
                        item.AdminID = int.Parse(row["AdminID"].ToString());
                    }
                    if (row["IsAuthority"].ToString() != "")
                    {
                        item.IsAuthority = int.Parse(row["IsAuthority"].ToString());
                    }
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = int.Parse(row["OrganID"].ToString());
                    }
                    if (row["OrganLevelID"].ToString() != "")
                    {
                        item.OrganLevelID = new int?(int.Parse(row["OrganLevelID"].ToString()));
                    }
                    if (row["OrganTypeID"].ToString() != "")
                    {
                        item.OrganTypeID = new int?(int.Parse(row["OrganTypeID"].ToString()));
                    }
                    if (row["OrganBuildID"].ToString() != "")
                    {
                        item.OrganBuildID = new int?(int.Parse(row["OrganBuildID"].ToString()));
                    }
                    item.OrganDescription = row["OrganDescription"].ToString();
                    item.OrganBranchCode = row["OrganBranchCode"].ToString();
                    item.PermitNo = row["PermitNo"].ToString();
                    item.Functions = row["Functions"].ToString();
                    if (row["PermitDate"].ToString() != "")
                    {
                        item.PermitDate = new DateTime?(DateTime.Parse(row["PermitDate"].ToString()));
                    }
                    item.BankName = row["BankName"].ToString();
                    item.BankID = row["BankID"].ToString();
                    item.OrganName = row["OrganName"].ToString();
                    item.LegalPerson = row["LegalPerson"].ToString();
                    if (row["PermitOrganCount"].ToString() != "")
                    {
                        item.PermitOrganCount = new int?(int.Parse(row["PermitOrganCount"].ToString()));
                    }
                    if (row["RealityOrganCount"].ToString() != "")
                    {
                        item.RealityOrganCount = new int?(int.Parse(row["RealityOrganCount"].ToString()));
                    }
                    item.Address = row["Address"].ToString();
                    item.Postcode = row["Postcode"].ToString();
                    item.Contact = row["Contact"].ToString();
                    item.Tel = row["Tel"].ToString();
                    item.Remark = row["Remark"].ToString();
                    if (row["AddDate"].ToString() != "")
                    {
                        item.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                    }
                    item.AddUser = row["AddUser"].ToString();
                    item.OrganName2 = row["OrganName2"].ToString();
                    item.BuildName = row["BuildName"].ToString();
                    item.LevelName = row["LevelName"].ToString();
                    item.RoleName = row["RoleName"].ToString();
                    item.TypeName = row["TypeName"].ToString();
                    item.ParentName = row["ParentName"].ToString();
                    item.PayWay = row["PayWay"].ToString();
                    if (row["IsOffice"].ToString() != "")
                    {
                        item.IsOffice = int.Parse(row["IsOffice"].ToString());
                    }
                    if (row["LevelNo"].ToString() != "")
                    {
                        item.LevelNo = new int?(int.Parse(row["LevelNo"].ToString()));
                    }
                    if (row["ParentID"].ToString() != "")
                    {
                        item.ParentID = new int?(int.Parse(row["ParentID"].ToString()));
                    }
                    item.OrganCode = row["OrganCode"].ToString();
                    if (row["OrganClassID"].ToString() != "")
                    {
                        item.OrganClassID = new int?(int.Parse(row["OrganClassID"].ToString()));
                    }
                    if (row["OrganRoleID"].ToString() != "")
                    {
                        item.OrganRoleID = new int?(int.Parse(row["OrganRoleID"].ToString()));
                    }
                    list.Add(item);
                }
            }
            return list;
        }
    }
}

